package com.wujie.section10;

/**
 * Created by wujieliu on 2017/10/27.
 */
public class WinnerState implements State {

    GumballMachine gumballMachine;

    public WinnerState(GumballMachine gumballMachine) {
        this.gumballMachine = gumballMachine;
    }

    public void insertQuarter() {
        System.out.println("winner insert error");
    }

    public void ejectQuarter() {
        System.out.println("winner eject error");
    }

    public void turnCrank() {
        System.out.println("winner turn error");
    }

    public void dispense() {
        System.out.println("You're a winner you get two gumball for your quarter");
        gumballMachine.releaseBall();
        if (gumballMachine.getCount() == 0) {
            gumballMachine.setState(gumballMachine.getSoldOutState());
        } else {
            gumballMachine.releaseBall();
            if (gumballMachine.getCount() > 0) {
                gumballMachine.setState(gumballMachine.getNoQuarterState());
            } else {
                gumballMachine.setState(gumballMachine.getSoldOutState());
            }
        }

    }
}
